package com.example.experiment07.exception;

import com.example.experiment07.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description:
 * @author: YancyZhang
 * @time: 2022/6/21 15:59
 */
@Slf4j
@RestControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(MyException.class)
    public ResultVO handleValidException(MyException exception) {
        return ResultVO.error(exception.getCode(), exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleException(Exception exception) {
        return ResultVO.error(400, "请求错误: " + exception.getMessage());
    }
}